import json

students = {}  # 定义一个空字典
while True:
    do = input("请你输入想完成的操作(添加|修改|删除|查询|退出)")
    if do == "添加":
        id = input("请输入学号:")
        name = input("请输入姓名:")
        age = input("请输入年龄:")
        # 将id name age存入一个字典，然后将字典写入文件
        students.update({id: {"姓名": name, "年龄": age}})
        with open("students", "w") as fp:
            # 将students字典转成json字符串，并写入文件
            json.dump(students, fp, ensure_ascii=False)
    elif do == "修改":
        pass
    elif do == "删除":
        pass
    elif do == "查询":
        # 将文件中的数据读取
        with open("students",'r') as fp:
            data = json.load(fp)
            print(data)
    elif do == "退出":
        break
